﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using BOMS.Model;

namespace BOMS.BLL
{
    public class BatteryAnaly

    {
        private readonly BOMS.DAL.BatteryAnaly dal = new BOMS.DAL.BatteryAnaly();

        /// <summary>
        /// 取电池或电池组的历史记录数据。key.BatteryID为-1时，表电池组。
        /// 抽样（间隔>3秒）或实际（间隔=3秒）
        /// </summary>
        /// <param name="key">组合主键</param>
        /// <param name="param"></param>
        /// <param name="PageCount"></param>
        /// <returns>
        /// key.BatteryID=-1时，返回电池组历史表：(Vval,Ival,CapFree,LogID,Dtm,ID)
        /// key.BatteryID!=-1时，返回电池历史表：(Vval,Rval,Tval,LogID,Dtm,ID)
        /// </returns>
        public List<BOMS.Model.BatteryAnaly> GetBatteryAbstractData(BatteryKey key,
            AnalyParam param, out int PageCount)
        {
            DataSet ds = dal.GetBatteryAbstractData(key, param, out PageCount);
            return DataTableToList(ds.Tables[0]);
        }
         /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<BOMS.Model.BatteryAnaly> DataTableToList(DataTable dt)
        {
            List<BOMS.Model.BatteryAnaly> modelList = new List<BOMS.Model.BatteryAnaly>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                BOMS.Model.BatteryAnaly model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.BatteryAnaly();
                    dal.AssignModel(dt.Rows[n], model);
                    modelList.Add(model);
                }
            }
            return modelList;
        }
    }
}
